package oop.core.med;
import oop.core.Scheduler;
import oop.core.map.*;
import oop.core.skill.SkillObject;
import oop.core.entity.*;
import java.util.*;

/**
 * This class is meant for handling what happens when a collision occurs
 *	@author DangMH
 */
public class SkillCollisionHandler 
{
	private List<Entity> entitiesList;
	private Avatar avatar;
	private Map<Location, SkillObject> skillObjectMap;
	private Scheduler scheduler;
	
	/**
	 * Empty constructor
	 */
	public SkillCollisionHandler()
	{
		entitiesList = new ArrayList<Entity>();
		skillObjectMap = new HashMap<Location, SkillObject>();
	}
	
	/**
	 * Parameterized constructor
	 * @param entitiesList
	 * @param skillObjectMap
	 */
	public SkillCollisionHandler(List<Entity> entitiesList, Map<Location, SkillObject> skillObjectMap, Avatar avatar, Scheduler scheduler)
	{
		this.entitiesList = entitiesList;
		this.skillObjectMap = skillObjectMap;
		this.avatar = avatar;
		this.scheduler = scheduler;
	}
	
	/**
	 * Collision handling using SkillObject doEffect() interface.
	 * @param locations
	 */
	public void handleCollisions( List<Location> locations )
	{
		if( locations.contains( avatar.getLoc() ) )
		{
			SkillObject so = skillObjectMap.get( avatar.getLoc() );
			if( so != null && scheduler != null && so.doEffect( avatar ) )
			{
				System.out.println( "Doing effect on: " + avatar.toString() );
				scheduler.register( so, so.getDelay() );
			}
		}
		
		for( Entity e : entitiesList )
		{
			Location loc = e.getLoc();
			if( locations.contains( loc ) )
			{
				SkillObject so = skillObjectMap.get( loc );
				if( so.doEffect(e) )
				{
					System.out.println( "Doing effect on: " + e.toString() );
					scheduler.register( so, so.getDelay() );
				}
			}
		}
	}
}
